/*
 *  Copyright (C) 2010:
 *                 Buzzanca Marco <marco.bzn@gmail.com>
 *         Monaco Davide Giuseppe <black.ralkass@gmail.com>
 *              Petralia Veronica <veronicapetralia@gmail.com>
 *
 * This file is part of DS2011BMP
 *
 * DS2011BMP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DS2011BMP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 * NOTE: this file should not be included directly,
 *       Include discoveryproxyfactory.h instead.
 */

/**
 * @file This file contains DiscoveryProxyFactory 
 *       class declaration and implementation.
 *
 * @author Marco Buzzanca
 */

#include <boost/shared_ptr.hpp>
#include <boost/cstdint.hpp>

#include "workerdiscoveryproxy.h"
#include "address.h"

typedef boost::shared_ptr<WorkerDiscoveryProxy> WorkerDiscoveryProxyPointer;

/**
 * DiscoveryProxyFactory
 *
 * DiscoveryProxyFactory is invoked by the manager in order to obtain the
 * instance of WorkerDiscoveryProxy, needed to communicate with the Discovery
 * node.
 */
class DiscoveryProxyFactory
{
private:
    /**
     * @brief Discovery node address.
     */
    Address _discovery_addr;

public:
    /**
     * @brief Default constructor.
     */
    DiscoveryProxyFactory(void)
      : _discovery_addr("localhost", 13000) { }

    /**
     * @brief Configures the factory to build proxies with specified IP and
     *        port.
     *
     * @param discoveryIP   Provided Discovery IP address. 
     * @param discoveryPort Provided Discovery port.
     */
    inline DiscoveryProxyFactory(const std::string& discoveryIP,
                                 boost::uint16_t discoveryPort)
      : _discovery_addr(discoveryIP, discoveryPort) { }

    /**
     * @brief Configures the factory to build proxies with specified address.
     * @param discoveryAddress Provided Discovery Address object.
     */
    inline DiscoveryProxyFactory(const Address& discoveryAddress)
      : _discovery_addr(discoveryAddress) { }

    /**
     * @brief Destructor.
     */
    inline ~DiscoveryProxyFactory(void) { }

    /**
     * @brief Gets discovery node address.
     * @return Discovery Address object.
     */
    inline const Address& getDiscoveryAddress(void)
    { return _discovery_addr; }

    /**
     * @brief Sets discovery node address with provided IP and Port.
     * @param discoveryIP   Provided Discovery IP address. 
     * @param discoveryPort Provided Discovery port.
     */
    inline void setDiscoveryAddress(const std::string& discoveryIP,
                                    boost::uint16_t discoveryPort)
    { _discovery_addr = Address(discoveryIP, discoveryPort); }

    /**
     * @brief Sets discovery node address with provided address.
     * @param discoveryAddress Provided Discovery Address object.
     */
    inline void setDiscoveryAddress(const Address& discoveryAddress)
    { _discovery_addr = discoveryAddress; }

    /**
     * @brief Gets pointer to a constructed proxy object.
     * @return A pointer to a new WorkerDiscoveryProxy.
     */
    inline WorkerDiscoveryProxyPointer getProxy(void)
    {
        return WorkerDiscoveryProxyPointer
            (new WorkerDiscoveryProxy(_discovery_addr));
    }

};
